package com.disapand.dingdang.controller

import com.disapand.dingdang.dto.RoleDTO
import com.disapand.dingdang.service.RoleService
import com.disapand.dingdang.vo.ResponseVO
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

/**
 * @author disapand
 * @date 2022/3/9 - 20:34 星期三
 */
@RestController
@RequestMapping("/role", name = "角色相关资源")
class RoleController(private val service: RoleService) {

    @PostMapping("/role", name = "添加或更新角色信息")
    fun save(
        @RequestBody dto: RoleDTO
    ): ResponseVO {
        service.save(dto)
        return ResponseVO.ofSuccess()
    }

    @GetMapping("/role", name = "根据 id 获取角色信息")
    fun find(@RequestParam id: Int): ResponseVO {
        return ResponseVO.ofSuccess(service.getById(id))
    }
}